package cn.tmpan.util;
import java.util.Random;

public class RadomStrUtil {
        public static char getRandomCharacter(char ch1,char ch2){
            return (char)(ch1+Math.random()*(ch2-ch1+1));//因为random<1.0，所以需要+1，才能取到ch2
        }
        public static char getRandomLowerCaseLetter(){
            return getRandomCharacter('a','z');
        }
        public static char getRandomUpperCaseLetter(){
            return getRandomCharacter('A','Z');
        }
        public static char getRandomDigitLetter(){
            return getRandomCharacter('0','9');
        }

        public static char getRandomCharacter(){
            return getRandomCharacter('\u0000','\uFFFF');
        }
        public static String getRandomStr(int length) {
            String base = "abcdefghijklmnopqrstuvwxyz0123456789";
            int randomNum;
            char randomChar;
            Random random = new Random();
            StringBuffer str = new StringBuffer();
            for (int i = 0; i < length; i++) {
                randomNum = random.nextInt(base.length());
                randomChar = base.charAt(randomNum);
                str.append(randomChar);
            }
            return str.toString();
        }
}
